"""
开放商户 - 变更服务
"""

from jlpay.services.base_service import BaseService
from jlpay.model.openmerch.change.merch_info_change import MerchInfoChangeRequest, MerchInfoChangeResponse
from jlpay.model.openmerch.change.rate_info_change import RateInfoChangeRequest, RateInfoChangeResponse
from jlpay.model.openmerch.change.settle_account_change import SettleAccountChangeRequest, SettleAccountChangeResponse
from jlpay.model.openmerch.change.fixed_withdraw_modify import FixedWithdrawModifyRequest, FixedWithdrawModifyResponse
from jlpay.model.openmerch.change.settle_rule_modify import SettleRuleModifyRequest, SettleRuleModifyResponse
from jlpay.model.openmerch.change.sign_info_modify import SignInfoModifyRequest, SignInfoModifyResponse


class ChangeService(BaseService):
    """开放商户变更服务"""
    
    def __init__(self, config):
        """
        初始化变更服务
        
        Args:
            config: OrgConfig实例
        """
        super().__init__(config)
    
    def get_api_url(self, request_class, api_path=None):
        """
        获取API URL
        
        Args:
            request_class: 请求类
            api_path: 接口路径
            
        Returns:
            完整的API URL
        """
        base_url = self.config.url
        
        if api_path:
            return f"{base_url}{api_path}"
        
        # 直接使用Request类中定义的完整API路径
        api_url = getattr(request_class, 'API_URL', '')
        
        if not api_url:
            # 如果没有定义API_URL，使用默认路径
            return f"{base_url}/open/merch/access"
        
        # 直接返回完整路径
        return f"{base_url}{api_url}"
    
    def change_merch_info(self, request: MerchInfoChangeRequest) -> MerchInfoChangeResponse:
        """
        变更商户信息
        
        Args:
            request: MerchInfoChangeRequest实例
            
        Returns:
            MerchInfoChangeResponse: 商户信息变更响应
        """
        return self.post(request, MerchInfoChangeResponse)
    
    def change_rate_info(self, request: RateInfoChangeRequest) -> RateInfoChangeResponse:
        """
        变更费率信息
        
        Args:
            request: RateInfoChangeRequest实例
            
        Returns:
            RateInfoChangeResponse: 费率信息变更响应
        """
        return self.post(request, RateInfoChangeResponse)
    
    def change_settle_account(self, request: SettleAccountChangeRequest) -> SettleAccountChangeResponse:
        """
        变更结算账户
        
        Args:
            request: SettleAccountChangeRequest实例
            
        Returns:
            SettleAccountChangeResponse: 结算账户变更响应
        """
        return self.post(request, SettleAccountChangeResponse)
    
    def modify_fixed_withdraw(self, request: FixedWithdrawModifyRequest) -> FixedWithdrawModifyResponse:
        """
        修改商户定点清算
        
        Args:
            request: FixedWithdrawModifyRequest实例
            
        Returns:
            FixedWithdrawModifyResponse: 定点清算修改响应
        """
        return self.post(request, FixedWithdrawModifyResponse)
    
    def modify_settle_rule(self, request: SettleRuleModifyRequest) -> SettleRuleModifyResponse:
        """
        修改商户结算规则
        
        Args:
            request: SettleRuleModifyRequest实例
            
        Returns:
            SettleRuleModifyResponse: 结算规则修改响应
        """
        return self.post(request, SettleRuleModifyResponse)
    
    def modify_sign_info(self, request: SignInfoModifyRequest) -> SignInfoModifyResponse:
        """
        修改商户签约信息
        
        Args:
            request: SignInfoModifyRequest实例
            
        Returns:
            SignInfoModifyResponse: 签约信息修改响应
        """
        return self.post(request, SignInfoModifyResponse) 